package com.example.myapplication.status2;

public class StatusContext {
    StatusChangeView view;

    public StatusContext(StatusChangeView view) {
        this.view = view;
    }

    public Status getStatus() {
        return status;
    }

    private Status status;

    public void setStatus(Status status) {
        this.status = status;
    }

    public void changeEvent(Event event) {
        if (null == status) {
            status = new StatusDownloading(this);
        }
        status.doAction();
    }

    public void updateView(Event event) {
        String status = null;
        switch (event) {
            case DOWNLOADING:
                status = "下载中";
                break;
            case DOWNLOAD_FAILED:
                status = "下载失败";
                break;
            case INSTALL:
                status = "安装中";
                break;
            case INSTALL_FAILED:
                status = "安装失败";
                break;
            case OPEN:
                status = "打开";
                break;
        }
        System.out.println("更新view*** " + status);
        view.updateView(status);
    }

    public void doAction(Event event) {
        switch (event) {
            case DOWNLOADING:
                break;
            case DOWNLOAD_FAILED:
                break;
            case INSTALL:
                break;
            case INSTALL_FAILED:
                break;
            case OPEN:
                break;
        }
    }
}
